//
//  DHS2_PreOrder_WashingCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/10.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHS2_PreOrder_WashingCell.h"
#import "DHS2_PreOrder_Washing_ItemCell.h"
#import "DHContactViewController.h"

@interface DHS2_PreOrder_WashingCell()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *tLabel;
@property (weak, nonatomic) IBOutlet UIButton *changeButton;

@property (strong, nonatomic) NSArray *arr;

@end

@implementation DHS2_PreOrder_WashingCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"DHS2_PreOrder_Washing_ItemCell" bundle:nil] forCellReuseIdentifier:kDHS2_PreOrder_Washing_ItemCell];
}

- (NSArray *)arr{
    if (!_arr) {
        _arr = [NSArray array];
    }
    return _arr;
}

- (void)updateCell:(NSDictionary *)dic{
    self.arr = [dic objectForKey:@"washing"];
    [self.tableView reloadData];
    
    NSDictionary *washing_return = [dic objectForKey:@"washing_return"];
    if (washing_return) {
        self.nameLabel.text = [NSString stringWithFormat:@"%@%@%@%@",[washing_return objectForKey:@"province"],[washing_return objectForKey:@"city"],[washing_return objectForKey:@"district"],[washing_return objectForKey:@"address"]];
        self.phoneLabel.text = [NSString stringWithFormat:@"%@  %@",[washing_return objectForKey:@"contact"],[washing_return objectForKey:@"phone"]];
    }
    
    if (self.isDetail) {
        self.changeButton.hidden = YES;
    }
}

- (IBAction)changeAction:(id)sender {
    if (!self.isDetail) {
        DHContactViewController *addressController = [[DHContactViewController alloc] init];
        addressController.isReturn = YES;
        [self.viewController.navigationController pushViewController:addressController animated:YES];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DHS2_PreOrder_Washing_ItemCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHS2_PreOrder_Washing_ItemCell forIndexPath:indexPath];
    NSDictionary *dic = [self.arr objectAtIndex:indexPath.row];
    cell.nameLabel.text = [dic objectForKey:@"name"];
    cell.countLabel.text = [NSString stringWithFormat:@"%@件",[dic objectForKey:@"count"]];
    cell.priceLabel.text = [NSString stringWithFormat:@"￥%.2f",[[dic objectForKey:@"wash_price"] floatValue]];
    return cell;
}

@end
